package com.cheng.web.action.base;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;

import com.cheng.bos.actionUtils.ActionUtils;
import com.cheng.domain.base.Standard;
import com.cheng.service.base.StandardService;
import com.opensymphony.xwork2.ActionContext;

@Namespace("/standard")
@ParentPackage("json-default")
@Controller
@Scope("prototype")
@Actions
public class StandardAction extends ActionUtils<Standard>{
	

	@Autowired
	private StandardService standardService;
	
	@Action(value="addstandard",results={@Result(name="success",type="redirect",location="../pages/base/standard.html")})
	public String addStandard(){
		standardService.addStandard(model);
		return SUCCESS;
	}

	@Action(value="findstandard",results={@Result(name="success",type="json")})
	public String findStandard(){
		//得到分页实体的对象
		Pageable pageable = new PageRequest(page-1, rows);
		//调用业务层进行分页查找得到分页查询结果对象
		Page<Standard> list = standardService.findAllStandardBypage(pageable);
		//将值压入值栈
		pushPageDataToValueStack(list);
		return SUCCESS;
	}
	@Action(value="allstandard",results={@Result(name="success",type="json")})
	public String findAllStandard(){
		List<Standard> list = standardService.findAllStandard();
		ActionContext.getContext().getValueStack().push(list);
		return SUCCESS;
	}
}
